package com.xuecheng.system.controller;

import com.xuecheng.commons.model.vo.CompanyVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.AuthInfoThreadLocal;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.system.domain.Company;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xuecheng.system.service.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 教育机构前端控制器
 * </p>
 *
 * @author 七安
 */
@Slf4j
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 查询机构
     *
     * @return 机构信息
     */
    @GetMapping("/mine")
    public ResponseResult<CompanyVo> mine() {
        //从本地线程中获取CompanyId
        Long companyId = AuthInfoThreadLocal.getCompanyId();
        //根据id查询机构信息
        Company company = companyService.getById(companyId);
        //对象内容转换
        CompanyVo companyVo = BeanHelper.copyProperties(company, CompanyVo.class);
        return ResponseResult.okResult(companyVo);
    }
}
